<?php

namespace app\adminapi\controller\v1\posts;

use app\adminapi\controller\AuthController;
use app\dao\system\attachment\SystemAttachmentDao;
use app\generator\CuteNicknameGenerator;
use app\Request;
use app\services\posts\PostCommentsServices;
use app\services\posts\PostsServices;
use app\services\posts\PostsTypeServices;
use app\services\user\UserServices;
use think\facade\App;

class PostsTypeController extends AuthController
{
    /**
     * PostsTypeServices constructor.
     * @param App $app
     * @param PostsTypeServices $service
     * @method temp
     */
    public function __construct(App $app, PostsTypeServices $service)
    {
        parent::__construct($app);
        $this->services = $service;
    }

    /**
     * 帖子分类列表
     * @param Request $request
     * @return mixed
     */
    public function list(Request $request){
        $dataList = $this->services->selectList(['is_del' => 0]);
        return app('json')->success("查询成功", $dataList->toArray());
    }


    /**
     * 添加帖子分类
     * @param Request $request
     * @return mixed
     */
    public function add(Request $request){
        $where = $request->postMore([
            ['post_type_name', '']
        ]);
        $this->services->save($where);
        return app("json")->success("添加成功");
    }

    /**
     * 修改帖子分类
     * @param Request $request
     * @return mixed
     */
    public function edit(Request $request) {
        $where = $request->postMore([
            ['id', ''],
            ['post_type_name', '']
        ]);
        $this->services->update($where['id'], $where);
        return app("json")->success("修改成功");
    }


    /**
     * 删除帖子分类
     * @param Request $request
     * @return mixed
     */
    public function delete(Request $request) {
        $where = $request->postMore([
            ['id', 0]]
        );
        $this->services->update($where['id'],['is_del' => 1]);
        return app("json")->success("删除成功");
    }
}